package com.sskj.mine.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.util.CommonUtil;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.ui.activity.SettingPasswordActivity;


/**
 * @author Hey
 * Create at  2019/05/01
 */
public class SettingPasswordPresenter extends BasePresenter<SettingPasswordActivity> {

    //重置资金密码  登录密码
    public void setPayPwd(String password, String password_confirmation, String code,String google_code) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SET_PAY_PWD)
                .params("password", CommonUtil.getFiveMd5Value(password))
                .params("password_confirmation", CommonUtil.getFiveMd5Value(password_confirmation))
                .params("code", code)
                .params("google_code", google_code)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        ToastUtil.showShort(httpListData.getMsg());
                        if (httpListData.getStatus() == 200) {
                            mView.updataUI();
                        }
                    }
                });
    }

    //重置资金密码  登录密码
    public void updatePayPwdOrLoginPwd(String oldPwd, String pwd1, String code, boolean isPayPwd,String google_code) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.UPDATE_PAY_OR_LOGIN_PWD)
                .params("type", isPayPwd ? "payment" : "password")
                .params("old_password", CommonUtil.getFiveMd5Value(oldPwd))
                .params("password", CommonUtil.getFiveMd5Value(pwd1))
                .params("password_confirmation", CommonUtil.getFiveMd5Value(pwd1))
                .params("code", code)
                .params("google_code", google_code)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        ToastUtil.showShort(httpListData.getMsg());
                        if (httpListData.getStatus() == 200) {
                            mView.updataUI();
                        }
                    }
                });
    }
}
